package com.gexiaobao.pigeon.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.MallShopListResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.makeramen.roundedimageview.RoundedImageView

/**
 * @Author      : hxw
 * @Date        : 2024/3/26 10:24
 * @Describe    :
 */
class ShopGoodsItemAdapter(data: ArrayList<MallShopListResponse.ListBean.GoodListBean>) :
    BaseQuickAdapter<MallShopListResponse.ListBean.GoodListBean, BaseViewHolder>(R.layout.item_shop_goods_image, data) {

    private val radius = 25

    override fun convert(holder: BaseViewHolder, item: MallShopListResponse.ListBean.GoodListBean) {
        val ivImageGoods = holder.getView<RoundedImageView>(R.id.itemShopGoodsImage)

        holder.setText(R.id.tvGoodsPrice, "¥" + item.salePrice)
        if (data.size == 1) {
            ImageLoaderManager.loadRoundImage(context, item.goodImg, ivImageGoods, radius)
        } else {
            when (holder.layoutPosition) {
                0 -> {
                    ImageLoaderManager.loadRoundImageLeft(context, item.goodImg, ivImageGoods, radius)
                }

                data.size - 1 -> {
                    ImageLoaderManager.loadRoundImageRight(context, item.goodImg, ivImageGoods, radius)
                }

                else -> {
                    ImageLoaderManager.loadRoundImage(context, item.goodImg, ivImageGoods, 1)
                }
            }
        }
    }
}